package com.googlecode.wicketcharts.highcharts.gson;

import java.lang.reflect.Type;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.googlecode.wicketcharts.highcharts.options.Symbol;

/**
 * Serializer for the {@link Symbol} class.
 * 
 * @author Tom Hombergs (tom.hombergs@gmail.com)
 * 
 */
public class GsonSymbolSerializer implements JsonSerializer<Symbol> {

	@Override
	public JsonElement serialize(Symbol src, Type typeOfSrc,
			JsonSerializationContext context) {
		if (src.getPredefinedSymbol() != null) {
			return new JsonPrimitive(src.getPredefinedSymbol().getCode());
		} else if (src.getUrl() != null) {
			return new JsonPrimitive("url(" + src.getUrl() + ")");
		} else {
			return null;
		}
	}

}
